package com.wnhz.work.jy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.wnhz.work.jy.BaseActivity;
import com.wnhz.work.jy.MyMain;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.PurchaseCodeResult;
import com.wnhz.work.jy.bean.ShoppingBean;

import java.util.ArrayList;

/**
 * ---选择支付方式
 */
public class ChoosePayActivity extends BaseActivity implements View.OnClickListener {
    private TextView title;
    private ArrayList<ShoppingBean> list;
    private String allPrice;
    private String goodsId;//购物车id
    private PurchaseCodeResult purchaseCodeResult;
    private TextView text;
    private TextView view_main_right_text;

    private String addType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_pay);

        initData();
        initView();
        if (purchaseCodeResult != null) {
            text.setText("第一步：选择获取方式");
            view_main_right_text = (TextView) findViewById(R.id.view_main_right_text);

            title.setText("选择获取方式");
            view_main_right_text.setText("取消");
            findViewById(R.id.btn_main_left).setVisibility(View.GONE);
            findViewById(R.id.btn_main_right).setVisibility(View.VISIBLE);
            findViewById(R.id.btn_main_right).setOnClickListener(this);
        }
        title.setText("选择获取方式");
    }

    private void initData() {
        list = (ArrayList<ShoppingBean>) getIntent().getSerializableExtra("list");
        allPrice = getIntent().getStringExtra("allPrice");
        addType = getIntent().getStringExtra("addType");
        goodsId = getIntent().getStringExtra("goodsId");
        purchaseCodeResult = (PurchaseCodeResult) getIntent().getSerializableExtra("purchaseCodeResult");
    }

    private void initView() {
        text = (TextView) findViewById(R.id.text);
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("支付");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.rl_reserve).setOnClickListener(this);
//        findViewById(R.id.rl_take_out).setOnClickListener(this);
        findViewById(R.id.rl_send).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;

            //存入金库
            case R.id.rl_reserve:
                if (purchaseCodeResult == null) {
                    intent = new Intent(ChoosePayActivity.this, OrderActivity.class);
                    intent.putExtra("jump", "1");
                    intent.putExtra("list", list);
                    intent.putExtra("obtainType", "0");
                    intent.putExtra("allPrice", allPrice);
                    intent.putExtra("addType", addType);
                    startActivity(intent);
                } else {
                    //purchaseCodeResult.setDelivery("0");
                }

                break;

          /*  //网点提取
            case R.id.rl_take_out:
                intent = new Intent(ChoosePayActivity.this, OrderActivity.class);
                intent.putExtra("jump", "2");
                intent.putExtra("list", list);
                intent.putExtra("obtainType", "6");
                intent.putExtra("allPrice", allPrice);
                startActivity(intent);
                break;*/

            //线下寄送
            case R.id.rl_send:
                if (purchaseCodeResult == null) {
                    intent = new Intent(ChoosePayActivity.this, OrderActivity.class);
                    intent.putExtra("jump", "3");
                    intent.putExtra("list", list);
                    intent.putExtra("obtainType", "1");
                    intent.putExtra("allPrice", allPrice);
                    intent.putExtra("addType", addType);
                    startActivity(intent);
                } else {
                    //purchaseCodeResult.setDelivery("1");
                    startActivity(new Intent(ChoosePayActivity.this, PurchaseCodeThirdly.class).putExtra("purchaseCodeResult", purchaseCodeResult));
                }

                break;
            case R.id.btn_main_right:
                startActivity(new Intent(ChoosePayActivity.this, MyMain.class).putExtra("Pagination", 4));
                break;

            default:
                break;
        }
    }
}
